import sqlite3
import random

def sad_sentences():
    data_path="./static/database/sad_sentence.db"
    conn=sqlite3.connect(data_path)
    cursor=conn.execute("SELECT  ID, TEXT, EMOTION from SENTENCES")
    sentence=[]
    emotion=[]
    for row in cursor:
        sentence.append(row[1])
        emotion.append(row[2])
    ans=[]

    for i in range(len(sentence)):
        if len(sentence[i])<=95:
            temp = {}
            temp['content']=sentence[i]
            temp['label']=emotion[i]
            # print(temp)
            ans.append(temp)
    random.shuffle(ans)
    return ans

class SourceDataDemo:

    def __init__(self):

        # 默认的标题
        self.title = '基于多源数据融合的抑郁情况可视化及言论评估系统'
        # 两个小的form看板
        self.counter = {'name': '2018年总收入情况', 'value': 88880000}
        self.counter2 = {'name': '2018年总支出情况', 'value': 66660000}
        # 总共是6个图表，数据格式用json字符串，其中第3个图表是有3个小的图表组成的
        self.echart1_data = {
            'title': '微博24小时抑郁相关度变化指数',
            'data': [
                {"name": "指数", "value":[543,412,362,250,235,222,223,256,308,423,563,623,685,792,876,820,750,650,700,803,823,885,850,752,652]},
            ],
            'xAxis': ["0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
           "19", "20", "21", "22", "23", "24"],

        }
        self.echart2_data = {
            'title': '世界人口总量',
            'data': [
                {"name": "巴西", "value": 182},
                {"name": "印尼", "value": 234},
                {"name": "美国", "value": 290},
                {"name": "印度", "value": 1049},
                {"name": "中国", "value": 1317},
                {"name": "世界人口", "value": 6302},
            ]
        }
        self.echart3_data = {

            'title': '近年抑郁关注度变化趋势',
            'data': [
                {"name": "关注度", "value": [120, 123, 225, 330, 409, 370, 289, 281, 310, 463, 611, 554]},
                {"name": "关注度指数", "value": [7.0588235294117645, 7.235294117647059, 13.235294117647058, 19.41176470588235, 24.058823529411764, 21.764705882352942, 17.0, 16.529411764705884, 18.235294117647058, 27.235294117647058, 35.94117647058823, 32.588235294117645]},
            ],
            'xAxis': ["2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020"],

        }

        self.echart4_data = {
            'title': '抑郁类型及占比',
            'data': [
                {"name": "产后抑郁", "value": 1534},
                {"name": "青少年抑郁", "value": 3708},
                {"name": "工作压力", "value": 4986},
                {"name": "老龄化抑郁", "value": 1243},
                {"name": "疫情原因", "value": 465},
            ]
        }
        self.echart5_data = {
            'title': '省份TOP',
            'data': [
                {"name": "浙江", "value": 2},
                {"name": "上海", "value": 3},
                {"name": "江苏", "value": 3},
                {"name": "广东", "value": 9},
                {"name": "北京", "value": 15},
                {"name": "深圳", "value": 18},
                {"name": "安徽", "value": 20},
                {"name": "四川", "value": 13},
            ]
        }
        # 这是一个环状图，有颜色的加上没颜色的正好等于100，半径是外圈直径和内圈直径，猜测是左闭右开
        self.echart6_data = {
            'title': '”抑郁“词语关系与词频',
            "top": ['1990', '2015'],
            'data':
                [[12, 0.8632401704788208, '消退'], [3, 0.8522652268409729, '密集'], [61, 0.8499336123466492, '失眠'],
                 [71, 0.8441545248031616, '遭受'], [20, 0.8437997579574585, '荷尔蒙'], [17, 0.8429446697235107, '衰弱'],
                 [65, 0.8345832109451294, '强迫症'], [59, 0.8326718091964722, '自卑'], [5, 0.8304074883460999, '墨守成规'],
                 [188, 0.815735924243927, '极度'], [20, 0.8152477025985718, '转变'], [97, 0.8151822566986084, '程度'],
                 [63, 0.807347583770752, '引发'], [85, 0.8017521381378174, '低落'], [64, 0.79845755100250244, '极端'],
                 [101, 0.7972347319126129, '恶化'], [50, 0.7966561198234558, '起伏'], [8, 0.79639371037483215, '回首往事'],
                 [7, 0.78886969685554504, '无处不在']]

        }
        # 这个在哪里用了？？？
        self.map_1_data = {
            'symbolSize': 1000,
            'data': [
                {'name': '海门', 'value': 239},
                {'name': '鄂尔多斯', 'value': 231},
                {'name': '招远', 'value': 203},
            ]
        }


    @property
    def language(self):
        language = sad_sentences()
        data=[]
        for i in language:
            data.append(i)
        random.shuffle(data)
        return data


    @property
    def echart1(self):
        data = self.echart1_data
        echart = {
            'title': data.get('title'),
            'names': [i.get("name") for i in data.get('data')],
            'xAxis': data.get('xAxis'),
            'data': data.get('data'),
        }
        return echart

    @property
    def echart2(self):

        data = self.echart2_data
        echart = {
            'title': data.get('title'),
            'xAxis': [i.get("name") for i in data.get('data')],
            'series': [i.get("value") for i in data.get('data')]
        }

        return echart


    @property
    def echart3(self):
        data = self.echart3_data
        echart = {
            'title': data.get('title'),
            'names': [i.get("name") for i in data.get('data')],
            'value': [i.get("value") for i in data.get('data')],
            'xAxis': data.get('xAxis'),
            'types':data.get("types")
        }
        return echart



    @property
    def echart4(self):
        data = self.echart4_data
        echart = {
            'title': data.get('title'),
            'data': data.get('data')
        }
        return echart

    @property
    def echart5(self):
        data = self.echart5_data
        echart = {
            'title': data.get('title'),
            'xAxis': [i.get("name") for i in data.get('data')],
            'series': [i.get("value") for i in data.get('data')],
            'data': data.get('data'),
        }
        return echart

    @property
    def echart6(self):
        data = self.echart6_data
        echart = {
            'title': data.get('title'),
            'top': data.get('top'),
            'data': data.get('data'),
        }
        return echart

    @property
    def map_1(self):
        data = self.map_1_data
        echart = {
            'symbolSize': data.get('symbolSize'),
            'data': data.get('data'),
        }
        return echart


class SourceData(SourceDataDemo):

    def __init__(self):
        """
        按照 SourceDataDemo 的格式覆盖数据即可
        """
        super().__init__()
        self.title = '基于多源数据融合的抑郁情况可视化及言论评估系统'


